{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Simulating Probabilities [demonstration]\n",
    "The code below shows one method for simulating dice rolls. Read through it and try to understand how it works. \n",
    "\n",
    "**What does the data stored in `roll_counts` represent?**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 was rolled 163 times\n",
      "2 was rolled 159 times\n",
      "3 was rolled 170 times\n",
      "4 was rolled 160 times\n",
      "5 was rolled 172 times\n",
      "6 was rolled 176 times\n"
     ]
    }
   ],
   "source": [
    "# Import the random module and reference it as rd\n",
    "import random as rd\n",
    "\n",
    "\n",
    "def simulate_dice_rolls(N):\n",
    "    \"\"\"\n",
    "    Simulates dice rolls\n",
    "    \n",
    "    Args:\n",
    "        N (int): The number of trials\n",
    "        \n",
    "    Returns:\n",
    "        list: roll counts [1,6]\n",
    "    \"\"\"\n",
    "    # Create a list to track the 6 options for the roll\n",
    "    roll_counts = [0,0,0,0,0,0]\n",
    "    for i in range(N):\n",
    "        # Randomly select a value from the list (1 to 6)\n",
    "        roll = rd.choice([1,2,3,4,5,6]) \n",
    "        # Recall indices start at 0 so we need to decrement\n",
    "        index = roll - 1\n",
    "        roll_counts[index] = roll_counts[index] + 1\n",
    "    return roll_counts\n",
    "\n",
    "def show_roll_data(roll_counts):\n",
    "    \"\"\"\n",
    "    Shows the dice roll data\n",
    "    \n",
    "    Args:\n",
    "        roll_counts (list): The roll counts stored in the list\n",
    "        \n",
    "    Returns:\n",
    "        list: roll counts [1,6]\n",
    "    \"\"\" \n",
    "    # Gets the number of sides of the dice and prints\n",
    "    # the side of the die. \n",
    "    # enumerate creates the position of the die and the\n",
    "    # list value\n",
    "    for dice_side, frequency in enumerate(roll_counts):\n",
    "        print(dice_side + 1, \"was rolled\", frequency, \"times\")\n",
    "        \n",
    "roll_data = simulate_dice_rolls(1000)\n",
    "show_roll_data(roll_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Basic Data Visualization [optional]\n",
    "This section is optional but you may find it interesting.\n",
    "\n",
    "You'll learn more about this throughout the Nanodegree, but  now is a great time to look at one data visualization tool called a histogram."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXnUlEQVR4nO3deZhmZX3m8e8tDaLsS0HYWwxB0cuItCiD46AYx4URZsQMDhJEEpKMuAxuaJJBJ6PBmYQoYpwQQFsFlEEUXEZFFJUYkWYRWSQwpIGWrRVZmmgE/OWP8/ShaKqqq7u66lRXfT/XVVe9Z/+dt6Hu8zznfZ+TqkKSJIAnDF2AJGn2MBQkST1DQZLUMxQkST1DQZLUMxQkST1DQVOW5PAkX5+mfX8iyf+cjn2PcazXJ7lkJo41WyTZP8mNSVYkOWQd7/sx72eSSvKb6/IYWvcMBU1Kkhck+V6S+5Lck+TvkzwXoKrOrKqXzoIaL07y+9O4/42SvLf9EX0wydIkZyRZOF3HbMc9IMmyadr9/wBOqapNq+oLYxx7aZJftNC4s4X0ptNUi2YBQ0GrlWRz4EvAR4CtgZ2A9wH/MmRdAzgXeBXwX4AtgN8GLgcOHLKoKdoNuHY16/yHqtoUeDawN/Duaa9KgzEUNBm/BVBVZ1fVI1X1i6r6elVdDeN2E/zXdkX9QJI/T/LUJP+Q5P4k5yTZaKxtR23/uG6GJFsl+VKS5Ul+3l7v3Ja9H/i3wCntqvaUNv9pSS5srZsbkvzuqP1tk+SCVtMPgKeO9wYkeQnwO8DBVXVZVT1cVfdV1Uer6vS2zo5tf/ckuSnJH4za/j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Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Matplotlib is one of the most common plotting packages in Python\n",
    "# to use it more succinctly, you can call it   \n",
    "from matplotlib import pyplot as plt\n",
    "# This line is needed\n",
    "%matplotlib inline\n",
    "\n",
    "def visualize_one_die(roll_data):\n",
    "    \"\"\"\n",
    "    Visualizes the dice rolls\n",
    "    \n",
    "    Args:\n",
    "        roll_data (int): roll counts in a list from [1,6]\n",
    "        \n",
    "    Returns:\n",
    "        None - shows a plot with the x-axis is the dice values\n",
    "               and the y-axis as the frequency for t\n",
    "    \"\"\"\n",
    "    roll_outcomes = [1,2,3,4,5,6]\n",
    "    fig, ax = plt.subplots()\n",
    "    ax.bar(roll_outcomes, roll_data)\n",
    "    ax.set_xlabel(\"Value on Die\")\n",
    "    ax.set_ylabel(\"# rolls\")\n",
    "    ax.set_title(\"Simulated Counts of Rolls\")\n",
    "    plt.show()\n",
    "    \n",
    "roll_data = simulate_dice_rolls(500)\n",
    "visualize_one_die(roll_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
